package day05;
import java.util.Arrays;
import java.util.Random;

public class ArrayHomeWork {
    public static void main(String[] args) {
        Random rand = new Random();
        int[] arr = new int[]{36,48,55,15,2,8,3,6,1,88,26};
        int[] arr1 = new int[15];
        int[] arr2;
        arr2 = new int[10];
        System.out.println("数组的长度:"+arr.length);//11
        System.out.println("数组的访问:"+arr[6]);//3
        System.out.println("数组的遍历:");
        for ( int num =0; num < arr1.length; num++  ){
            arr1[num] = 69;
            System.out.print(arr1[num]+"\t");
        }
        System.out.println();
        System.out.println("数组的复制1:");
        System.arraycopy(arr,2,arr2,0,8);
        for (int i =0; i< arr2.length;i++){
            System.out.print(arr2[i]+"\t");
        }
        System.out.println();
        System.out.println("数组的复制2");
        int[] arr3 = new int[]{8,77,68,21,15,2,63,13,8};
        int[] arr4 = Arrays.copyOf(arr3,6);
        for(int j=0; j<arr4.length; j++){
            System.out.print(arr[j]+"\t");
        }
        System.out.println();
        //-------------------
        System.out.println("新数组: ");
        int[] arr5;
        arr5 = new int[10];
        for(int i=0; i<arr5.length; i++){
            arr5[i] = rand.nextInt(100);
            System.out.println(arr5[i]);
        }
        int max = arr5[0];
        for(int j=0; j<arr5.length; j++){
            if(arr5[j]>max){
                max = arr5[j];
            }
        }

        System.out.println("新数组的最大值: "+max);
        System.out.println("新数组的排序:");
        Arrays.sort(arr5);
        for(int j=0; j<arr5.length; j++){
            System.out.println(arr5[j]);
        }
        System.out.println("新数组的倒序:");
        for(int j=arr5.length-1; j>=0 ; j--){
            System.out.print(arr5[j]);
        }
        arr5= Arrays.copyOf(arr5,arr5.length+1);
        arr5[arr5.length-1]=max;
        System.out.println("最大值max赋值到最后一个元素:");
        for(int i=0; i<arr5.length; i++){
            System.out.println(arr5[i]);
        }
    }
}
